package com.lanxiao.cloud.common.web.config;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.lanxiao.cloud.common.core.service.IOperatorService;
import com.lanxiao.cloud.common.web.service.IContentParse;
import com.lanxiao.cloud.common.web.service.impl.DefaultContentParse;
import com.lanxiao.cloud.common.web.service.impl.OperatorServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @author ：qiaoliang
 * @date ：2021-08-20
 */
@EnableWebMvc
@Configuration
public class WebDataConvertConfig {

  @Bean("jackson2ObjectMapperBuilderCustomizer")
  public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
    return jacksonObjectMapperBuilder ->
        jacksonObjectMapperBuilder
        .serializerByType(Long.class, ToStringSerializer.instance)
        .serializerByType(Long.TYPE, ToStringSerializer.instance);
  }

  @Bean
  public DefaultContentParse defaultContentParse() {
    return new DefaultContentParse();
  }

  @Bean
  @ConditionalOnMissingBean
  public IOperatorService operatorService() {
    return new OperatorServiceImpl();
  }

}
